<?php

namespace App\Admin\Forms;

use App\Models\Order;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class RejectAfterSaleForm extends Form implements LazyRenderable
{
    use LazyWidget;
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $id = $this->payload['id'];

        $result =  Order::query()
                            ->where('id',$id)
                            ->update([
                                'reject_reason' => $input['reject_reason'],
                                'is_after_sale' => 4
                            ]);

        // return $this->response()->error('Your error message.');

        return $result ? $this
				->response()
				->success('拒绝售后成功')
				->refresh() : $this
                ->response()
            ->error('拒绝售后失败')
            ->refresh();



    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->textarea('reject_reason','拒绝售后原因')->rules('max:500',['max' => '最多输入500字'])->required();
    }

}
